﻿using AngleSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace htmlparser
{
  public  class farmersiteparser
    {
    
        public static async void Getnewlist()
        {
            IConfiguration config = Configuration.Default.WithDefaultLoader();
            var address = "http://www.farmer.com.cn/xwpd/btxw/";           
            var document = await BrowsingContext.New(config).OpenAsync(address);
            var lista = document.QuerySelectorAll("a.vvqqq");
            //var listelement = document.GetElementsByClassName("vvqqq");
            foreach (var a in lista)
            {
                string href = a.GetAttribute("href");
                string innertext = a.TextContent;
                Debug.WriteLine(href + innertext);
            }
        }
        public static async void GetnewlistNextpage(string url,string number)
        {
            IConfiguration config = Configuration.Default.WithDefaultLoader();
            var address = url+"/index_"+ number+".htm";
            var document = await BrowsingContext.New(config).OpenAsync(address);
            var lista = document.QuerySelectorAll("a.vvqqq");
            //var listelement = document.GetElementsByClassName("vvqqq");
            foreach (var a in lista)
            {
                string href = a.GetAttribute("href");
                string innertext = a.TextContent;
                Debug.WriteLine(href + innertext);
            }
        }
        public static async Task Getnewdetail(string href)
        {
            StringBuilder sb = new StringBuilder();
            IConfiguration config = Configuration.Default.WithDefaultLoader();
            var document = await BrowsingContext.New(config).OpenAsync(href);
            var divelement = document.GetElementsByClassName("Custom_UnionStyle");
            foreach(var p in divelement)
            {
                sb.Append(p.TextContent);
            }            
            Debug.WriteLine(sb.ToString());
        }
   }
}
